package com.example.redis.callback;

import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;

/**
 * 解锁
 *
 * @author xianxin
 * @since 2020/8/21
 */
@Slf4j
public class UnLockRedisCallback implements RedisCallback<Boolean> {

    private String lockKey;

    private String lockValue;

    public void setLockKey(String lockKey) {
        this.lockKey = lockKey;
    }

    public void setLockValue(String lockValue) {
        this.lockValue = lockValue;
    }

    @Override
    public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
        Long n = connection.del(this.lockKey.getBytes());
        log.info("解锁[{}][{}]", this.lockKey, n);
        return true;
    }
}
